import Vue from "vue";
import VueRouter from "vue-router";
import HomeView from "../views/HomeView.vue";

Vue.use(VueRouter);

const routes = [
  {
    path: "*", // 通配符：匹配所有找不到的路径
    name: "404",
    component: () => import("../views/NotFound.vue"),
  },
  {
    path: "/",
    name: "home",
    component: HomeView,
  },
  {
    // ? 代表参数可有可无，即可选参数
    path: "/list/:kw?",
    name: "list",
    component: () => import("../views/ListView.vue"),
  },
  {
    path: "/ditu",
    name: "Gaode",
    component: () => import("../views/indexGaode.vue"),
    meta: {
      title: "地图找房",
    },
  },
  {
    path: "/login",
    name: "login",
    component: () => import("../views/LoginView.vue"),
    meta: {
      title: "登录",
    },
  },
  {
    path: "/register",
    name: "register",
    component: () => import("../views/RegisterView.vue"),
    meta: {
      title: "注册",
    },
  },
  {
    path: '/wang',
    name: 'wang',
    component: () => import('../views/WangView.vue'),
  },
  {
    path: "/percenter",
    name: "percenter",
    component: () => import("../views/Per_Center.vue"),
    meta: {
      title: "个人中心",
    },
  },
  {
    path: "/publish",
    name: "Publish",
    component: () => import("../views/PublishView.vue"),
    meta: {
      title: "发布房源",
    },
  },
  {
    path: "/detail",
    name: "Detail",
    component: () => import("../views/DetailView.vue"),
    meta: {
      title: "房源详情页",
    },
  }
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,//我们可以将其与页面级过渡组件的事件挂钩，以使滚动行为与你的页面过渡很好地结合起来，但由于使用场景可能存在的差异和复杂性，我们只是提供了这个基础来实现特定的用户场景。
  //延迟滚动有时候，我们需要在页面中滚动之前稍作等待。例如，当处理过渡时，我们希望等待过渡结束后再滚动。要做到这一点，你可以返回一个 Promise，它可以返回所需的位置描述符。下面是一个例子，我们在滚动前等待 100ms：
  // scrollBehavior(to, from, savedPosition) {
  //   return new Promise((resolve, reject) => {
  //     setTimeout(() => {
  //       if (savedPosition) {
  //         resolve(savedPosition)
  //       } else {
  //         resolve({
  //           x: 0,
  //           y: 0,
  //         })
  //       }
  //     }, 100)
  //   })
  // },
})
router.afterEach((to,from,next) => {
  window.scrollTo(0,0);
})

export default router;
